const _ = require('lodash')

function clearFormat(str) {
    if (str && str[str.length - 1] === "/") {
        return str.substr(0, str.length - 1)
    } else {
        return str
    }
}

export default prefix => {
    return target => {
        target._type = "Controller"
        target.prototype._type = "Controller"
        target.prefix = prefix
        target.prototype.prefix = prefix
        //把前缀加上去
        var _reqList = {}
        _.map(target.prototype.reqList, (func, key) => {
            var method = key.split(":")[0]
            var methodName = key.split(":")[1]
            var key = key.split(":")[2]
            var _key = clearFormat(prefix + key)
            _reqList[`${method}:${methodName}:${_key}`] = func
        })
        target.prototype.reqList = _reqList
    }
}
